import request from '@/utils/request'

const module = '/admin/system/role'
// 查询角色分页列表
export const GetRoles = (pageNum, pageSize, roleName) => {
  return request({
    url: `${module}/list/${pageNum}/${pageSize}`,
    method: 'GET',
    //axios传所有的参数(头、体、请求参数)必须都是json对象
    params: { roleName }, // {roleName:roleName}
  })
}
//删除指定角色
export const DeleteRoleById = id => {
  return request({
    url: `${module}/deleteById/${id}`,
    method: 'DELETE',
  })
}
//新增角色
export const SaveRole = sysRole => {
  return request({
    url: `${module}/save`,
    method: 'POST',
    data: sysRole,
  })
}
//查询指定角色
export const GetRoleById = id => {
  return request({
    url: `${module}/getById/${id}`,
    method: 'GET',
  })
}
//更新角色
export const UpdateRole = sysRole => {
  return request({
    url: `${module}/update`,
    method: 'PUT',
    data: sysRole,
  })
}
//查询所有角色和已分配角色
export const GetAllRoles = userId => {
  return request({
    url: `${module}/allRoles/${userId}`,
    method: 'GET',
  })
}
//给角色分配菜单
export const AssignMenus2Role = (menuIds, roleId) => {
  return request({
    url: `/admin/system/roleMenu/assignMenus2Role/${roleId}`,
    method: 'PUT',
    data: menuIds,
  })
}
